package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.home.activity.DianShiDateilActivity;
import com.wuhan.template.module.home.entity.DianShiEntity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/12 0012.
 */
public class DianShiBaseAdapter extends MyBaseAdapter{
    private  List<DianShiEntity> dianShiLists;
    private Context context;
    private ImageLoader loader;
    private DisplayImageOptions options;
    public DianShiBaseAdapter(Context context, List dianShiLists) {
        super(context, dianShiLists);
        this.context = context;
        this.dianShiLists = dianShiLists;
        loader  = ((BaseApplication)(context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .cacheInMemory(true)
                .build();

    }

    @Override
    public int getLayoutId() {
        return R.layout.dianshi_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        ViewHolder holder = new ViewHolder();

        return holder;
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        final ViewHolder holder = (ViewHolder) viewHolder;
        String name = dianShiLists.get(holder.position).getName();
        holder.title.setText(name);
        DianShiEntity.CurProgramBean cur_program = dianShiLists.get(holder.position).getCur_program();
        holder.program.setText("当前:   " +cur_program.getProgram());
        String start_time = cur_program.getStart_time();
        String next_program = dianShiLists.get(holder.position).getNext_program().getStart_time();
        holder.time.setText("时间:  "+start_time+"~"+next_program);
        DianShiEntity.LogoBean logo = dianShiLists.get(holder.position).getLogo();
        String imageUrl= logo.getRectangle().getHost()+logo.getRectangle().getDir()+logo.getRectangle().getFilepath()+logo.getRectangle().getFilename();
        loader.displayImage(imageUrl,holder.imageLogo,options);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = dianShiLists.get(holder.position).getId();
                Intent intent = new Intent(context,DianShiDateilActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("dianshiId",id);
                intent.putExtra("m3u8",dianShiLists.get(holder.position).getM3u8());
                context.startActivity(intent);

            }
        });

    }

    public static class ViewHolder extends BaseViewHolder{
        @BindView(R.id.dianshi_logo)
        ImageView imageLogo;
        @BindView(R.id.dianshi_title)
        TextView title;
        @BindView(R.id.dianshi_program)
        TextView program;
        @BindView(R.id.dianshi_time)
        TextView time;
        @BindView(R.id.zhibo_stateImage)
        ImageView stateImage;

    }
}
